﻿using System;
using System.Collections.Generic;
//////using System.Linq;
using System.Web;

/// <summary>
/// Summary description for Cngay
/// </summary>
public class Cngay
{
	
		private int m_iNgay;
        private int m_iThang;
        private int m_iNam;

        public Cngay()
        {
            m_iNgay = 1;
            m_iThang = 1;
            m_iNam = 1;
        }
        public Cngay(int _iNgay,int _iThang,int _iNam)
        {
            m_iNgay = _iNgay;
            m_iThang = _iThang;
            m_iNam = _iNam;
        }
        public Cngay(Cngay cngay)
        {
            m_iNgay = cngay.m_iNgay;
            m_iThang = cngay.m_iThang;
            m_iNam = cngay.m_iNam;
        }

        public int NGAY
        {
            get { return m_iNgay; }
            set { m_iNgay = value; } 
        }
        public int THANG
        {
            get { return m_iThang; }
            set { m_iThang = value; }
        }
        public int NAM
        {
            get { return m_iNam; }
            set { m_iNam = value; }
        }

        public String ToString()
        {
            return m_iNgay.ToString() + "\\" + m_iThang.ToString() + "\\" + m_iNam.ToString();
        }

        public int SoNgayCuaThang(int _iThang)
        {
            int iSoNgay = 30;
            bool bThang31 = (_iThang == 1) || (_iThang == 3) || (_iThang == 5) || (_iThang == 7) || (_iThang == 8) || (_iThang == 10) || (_iThang == 12);
            bool bThang30 = (_iThang == 4) || (_iThang == 6) || (_iThang == 9) || (_iThang == 11);
            if (bThang31 == true)
            {
                iSoNgay = 31;
            }
            else if (bThang30 == true)
            {
                iSoNgay = 30;
            }
            else
            {
                if (XetNamNhuan(m_iNam) == true)
                {
                    iSoNgay = 29;
                }
                else
                {
                    iSoNgay = 28;
                }
            }
            return iSoNgay;
        }
        public int SoNgayCuaNam(int _iNam)
        {
            int iSoNgay = 365;
            if (XetNamNhuan(_iNam) == true)
            {
                iSoNgay = 366;
            }
            else
            {
                iSoNgay = 365;
            }
            return iSoNgay;
        }

        public bool XetNamNhuan(int _iNam)
        {
            bool bNamNhuan = false;
            bool bDieuKien1 = (_iNam % 400) == 0;
            bool bDieuKien2 = ((_iNam % 4) == 0) && ((_iNam % 100) != 0);
            if ((bDieuKien1 == true) || (bDieuKien2 == true))
            {
                bNamNhuan = true;
            }
            else
            {
                bNamNhuan = false;
            }
            return bNamNhuan;
        }

        public bool XetHopLe()
        {
            bool bHopLe = false;
            if ((m_iThang < 0) || (m_iThang > 12))
            {
                bHopLe = false;
            }
            else
            {
                int iSoNgayCuaThang = SoNgayCuaThang(m_iThang);
                if ((m_iNgay < 0) || (m_iNgay > iSoNgayCuaThang))
                {
                    bHopLe = false;
                }
                else
                {
                    bHopLe = true;
                }
            }
            return bHopLe;
        }
      
        
}